package io.github.uicdb.badskill.network;

import io.github.uicdb.badskill.BadSkill;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;

public class NetWorking {
    public static final String VERSION = "1.0";
    public static SimpleChannel simpleChannel;
    private static int ID = 0;

    public static int nextID() {
        return ID++;
    }

    public static void registerMessage() {
        simpleChannel = NetworkRegistry.newSimpleChannel(
                new ResourceLocation(BadSkill.MODID, "net_data"),
                () -> VERSION,
                (version) -> version.equals(VERSION),
                (version) -> version.equals(VERSION)
        );
        simpleChannel.messageBuilder(SkillOptionSyncPackage.class, nextID())
                .encoder(SkillOptionSyncPackage::toBytes)
                .decoder(SkillOptionSyncPackage::create)
                .consumerMainThread(SkillOptionSyncPackage::handle)
                .add();
        simpleChannel.messageBuilder(SkillPageSyncPackage.class, nextID())
                .encoder(SkillPageSyncPackage::toBytes)
                .decoder(SkillPageSyncPackage::create)
                .consumerMainThread(SkillPageSyncPackage::handle)
                .add();
        simpleChannel.messageBuilder(LearnCheckPackage.class, nextID())
                .encoder(LearnCheckPackage::toBytes)
                .decoder(LearnCheckPackage::create)
                .consumerMainThread(LearnCheckPackage::handle)
                .add();
        simpleChannel.messageBuilder(LearnResultPackage.class, nextID())
                .encoder(LearnResultPackage::toBytes)
                .decoder(LearnResultPackage::create)
                .consumerMainThread(LearnResultPackage::handle)
                .add();
        simpleChannel.messageBuilder(PlayerLearnedSyncPackage.class, nextID())
                .encoder(PlayerLearnedSyncPackage::toBytes)
                .decoder(PlayerLearnedSyncPackage::create)
                .consumerMainThread(PlayerLearnedSyncPackage::handle)
                .add();
        simpleChannel.messageBuilder(DisableSkillPackage.class, nextID())
                .encoder(DisableSkillPackage::toBytes)
                .decoder(DisableSkillPackage::create)
                .consumerMainThread(DisableSkillPackage::handle)
                .add();
        simpleChannel.messageBuilder(EnableSkillPackage.class, nextID())
                .encoder(EnableSkillPackage::toBytes)
                .decoder(EnableSkillPackage::create)
                .consumerMainThread(EnableSkillPackage::handle)
                .add();
        simpleChannel.messageBuilder(QueryAttributePackage.class, nextID())
                .encoder(QueryAttributePackage::toBytes)
                .decoder(QueryAttributePackage::create)
                .consumerMainThread(QueryAttributePackage::handle)
                .add();
        simpleChannel.messageBuilder(AtttributeValueSyncPackage.class, nextID())
                .encoder(AtttributeValueSyncPackage::toBytes)
                .decoder(AtttributeValueSyncPackage::create)
                .consumerMainThread(AtttributeValueSyncPackage::handle)
                .add();
        simpleChannel.messageBuilder(RetreatedResultPackage.class, nextID())
                .encoder(RetreatedResultPackage::toBytes)
                .decoder(RetreatedResultPackage::create)
                .consumerMainThread(RetreatedResultPackage::handle)
                .add();
        simpleChannel.messageBuilder(OnlySyncPackage.class, nextID())
                .encoder(OnlySyncPackage::toBytes)
                .decoder(OnlySyncPackage::create)
                .consumerMainThread(OnlySyncPackage::handle)
                .add();
        simpleChannel.messageBuilder(AllOnlySyncPackage.class, nextID())
                .encoder(AllOnlySyncPackage::toBytes)
                .decoder(AllOnlySyncPackage::create)
                .consumerMainThread(AllOnlySyncPackage::handle)
                .add();
    }
}
